|
![]() | |||
![]() |
|||
![]() | |||
|
![]() |
![]() | ||||||||||||||||||||||||||||||
Conditional statements: how to use "if" statements
A conditional statement is used to test the value of an expression and perform an action based on the result. A real world example of a conditional statement could be "If it is raining, I should bring my umbrella". The condition is whether or not it is raining. The action is whether or not I bring my umbrella. Conditional statements are invaluable when testing for specific scenarios in Director. For example, a conditional statement can test to see if a QuickTime movie is playing, and if it is not the Director movie will jump to a different frame. 'If' statements are most often used to test one condition. Nested if statements, which are discussed below, can be used to test more than one condition. 'Case' statements can test for two or more conditions. For more information about case statements, see Conditional statements: how to use "case" statements (TechNote16228). If
Statements By default, the condition is tested as true. The first example below can be translate to mean "if the condition (it is raining) is true, then (bring umbrella)". The third example below can be translated to "If the condition (it is NOT raining) is true, then (don't bring an umbrella)". Review the structure and examples below:
The following
three statements test to see if x is equal to true. Although they all look
different, they are testing for the same thing. Since they are all the
same, the result will always be an alert box with the word "true". In the
sample movie, each of these statements has a corresponding button.
This next
example can be attached to a button. In the sample movie the button
labeled "full script example" corresponds to this script. An alert
function is used, which, when executed, makes an alert box appear with the
specified text. On a mouseUp event, the script tests to see if x is true,
in which case an alert box pops up with the message "x=true". If x is not
equal to true, an alert box pops up with the message
"x=false". global x Nested 'if'
statements The terms "and" as well as "or" may be used in 'if' statements. The example script below shows the use of "and". The following script checks the value of the global variables x and y. Based on the values of these global variables, one of 4 alerts will appear. This script is attached to the button labeled "nested statement" in the sample movie. global x Resources Lingo Developer
Notes Note: This is just one of the
many ways to create this functionality in Director.
Download
the Windows zip file
|
![]() |
![]() |
Use of this website signifies your agreement to the Terms of Use. Privacy | Site Map | Contact us | Accessibility |